﻿using System;
using System.Collections.Generic;
using System.Text;
using MyPhotoIndex.Plugins.WebHost.RSS;
using MyPhotoIndex.ImageBank;
using MyPhotoIndex.Interfaces.Imaging;

namespace MyPhotoIndex.Plugins.WebHost.VirtualPages
{
    public class RSSFeed : VirtualPage
    {
        public override VirtualPage Clone()
        {
            return new RSSFeed();
        }

        public override void LoadPage()
        {
            ContentType = "text/rss";
        }

        public override void RenderPage(System.Web.UI.HtmlTextWriter writer)
        {
            throw new NotImplementedException();
        }

        public override void Render(System.Web.UI.HtmlTextWriter writer)
        {


            List<IImageData> list = new List<IImageData>();
            foreach (IImageData imageData in Storage.Instance.UnFiltered.Values)
            {
                list.Add(imageData);
                if (list.Count == 50)
                {
                    break;
                }
            }

            string basePath = this.Request.Url.Scheme + "://" + this.Request.Url.Host + ":" + this.Request.Url.Port;
            string rssFeed = MediaRSSSerializer.GetMediaRss(list.ToArray(), basePath, null);
            writer.Write(rssFeed);
        }
    }
}
